import axios from "axios";
import http from "@/api/http.js";
const baseUrl = "http://localhost:8091";
const incomingRequest={
//     分页查询
    loadSelectAllIncoming(incoming,page=1,limit=10,callBack){
        let url = baseUrl + "/incoming/selectAll?page=" + page + "&limit=" + limit;
        if (incoming){
            if (incoming.incomingId){
                url += "&incomingId=" + incoming.incomingId;
            }
            if (incoming.incomingSupplierId){
                url += "&incomingSupplierId=" + incoming.incomingSupplierId;
            }
            if (incoming.incomingSupplierName){
                url += "&incomingSupplierName=" + incoming.incomingSupplierName;
            }
            if (incoming.incomingItemId){
                url += "&incomingItemId=" + incoming.incomingItemId;
            }
            if (incoming.incomingItemName){
                url += "&incomingItemName=" + incoming.incomingItemName;
            }
            if (incoming.incomingMaterialOutcome){
                url += "&incomingMaterialOutcome=" + incoming.incomingMaterialOutcome;
            }
            if (incoming.incomingDate){
                url += "&incomingDate=" + incoming.incomingDate;
            }
            if (incoming.materialDate){
                url += "&materialDate=" + incoming.materialDate;
            }
            if (incoming.materialPerson){
                url += "&materialPerson=" + incoming.materialPerson;
            }
        }
        console.log(url)
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     新增来料检验单
    loadAddIncoming(incoming,callBack){
        let url = baseUrl + "/incoming/add";
        axios.post(url,incoming,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id查询检验单数据
    loadSelectIncomingById(incomingId,callBack){
        let url = baseUrl + "/incoming/selectById?incomingId=" + incomingId;
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id修改检验单数据
    loadUpdateIncoming(incoming,callBack){
        let url = baseUrl + "/incoming/update";
        axios.put(url,incoming,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     导出数据
    loadExportIncoming(incoming,page=1,limit=10,callBack){
        let url = baseUrl + "/incoming/export?page=" + page + "&limit=" + limit;
        if (incoming){
            if (incoming.incomingId){
                url += "&incomingId=" + incoming.incomingId;
            }
            if (incoming.incomingSupplierId){
                url += "&incomingSupplierId=" + incoming.incomingSupplierId;
            }
            if (incoming.incomingSupplierName){
                url += "&incomingSupplierName=" + incoming.incomingSupplierName;
            }
            if (incoming.incomingItemId){
                url += "&incomingItemId=" + incoming.incomingItemId;
            }
            if (incoming.incomingItemName){
                url += "&incomingItemName=" + incoming.incomingItemName;
            }
            if (incoming.incomingMaterialOutcome){
                url += "&incomingMaterialOutcome=" + incoming.incomingMaterialOutcome;
            }
            if (incoming.incomingDate){
                url += "&incomingDate=" + incoming.incomingDate;
            }
            if (incoming.materialDate){
                url += "&materialDate=" + incoming.materialDate;
            }
            if (incoming.materialPerson){
                url += "&materialPerson=" + incoming.materialPerson;
            }
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id删除数据
    loadDeleteIncomingById(incomingId,callBack){
        let url = baseUrl + "/incoming/delete?incomingId=" + incomingId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    }
}
export default incomingRequest;